#include "stdafx.h"
#include "playstate.h"
#include "gamemanager.h"
#include "map/MapManager.h"
#include "inputmanager.h"
#include "ObjectManager.h"
#include "Scene.h"
#include "terrain.h"
#include "guiKeeper.h"
#include "world.h"

CPlayState::CPlayState()
{

}

CPlayState::~CPlayState()
{

}

void CPlayState::RunOneFrame( int diff )
{
    CInputManager::Instance().Update(diff);
    CMapManager::Instance().Update(diff);
    sgWorld::Instance().Update(diff);
    CObjectManager::Instance().Update( diff );

    if(NULL==CD3DManager::Instance().GetDevice())
        return;
    CD3DManager::Instance().Clear();
    CD3DManager::Instance().BeginRender();

    CMapManager::Instance().RenderMap();
    CTerrain::Instance().Render();
    CObjectManager::Instance().Render();
    CScene::Instance().Render();

    sgGUI::sgGUIKeeper::Instance().drawOneFrame();

    CD3DManager::Instance().EndRender();
}

IGameState * CPlayState::Create()
{
    static CPlayState state;
    return &state;
}

void CPlayState::EnterState()
{
    guiKeeper.hideAll();
}

void CPlayState::ExitState()
{

}

CMenuState::CMenuState()
{

}

CMenuState::~CMenuState()
{

}

void CMenuState::RunOneFrame( int diff )
{
    if(NULL==CD3DManager::Instance().GetDevice())
        return;
    CD3DManager::Instance().Clear();
    CD3DManager::Instance().BeginRender();

    sgGUI::sgGUIKeeper::Instance().drawOneFrame();

    CD3DManager::Instance().EndRender();
}

IGameState * CMenuState::Create()
{
    static CMenuState state;
    return &state;
}

void CMenuState::EnterState()
{
    guiKeeper.hideAll();
    std::string panelName = "MainMenu";
    guiKeeper.showPanel( panelName );
}

void CMenuState::ExitState()
{

}

CExitState::CExitState()
{

}

CExitState::~CExitState()
{

}

void CExitState::RunOneFrame( int diff )
{
    CGameManager::Instance().OnExit( 0 );
    PostQuitMessage( 0 );
}

IGameState * CExitState::Create()
{
    static CExitState state;
    return &state;
}

void CExitState::EnterState()
{

}

void CExitState::ExitState()
{
    
}
